package com.example.a17376009_wangzehui_finaltest;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toolbar;

import org.w3c.dom.Text;

public class PetActivity  extends AppCompatActivity {
    public  static final PET_NAME="pet_name";
    public  static final PET_IMAGE_ID="pet_image_id";

    @Override
    protected  void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pet);
        Intent intent = getIntent();
        String petName = intent.getBooleanArrayExtra(PET_NAME);
        int petImageId = intent.getIntExtra(PET_IMAGE_ID, 0);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        ImageView petImageView = (ImageView) findViewById(R.id.pet_image_view);
        TextView petContentText = (TextView) findViewById(R.id.pet_content_text);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        collapsingToolbar.setTitle(petName);
        Glide.with(this).load(petImageId).into(petImageView);
        String petContent = generatePetContent(petName);
        petContentText.setText(petContent);
    }
    private String generatePetContent(String petName){
        StringBuilder petContent=new StringBuilder();
        for (int i=0;i<500;i++){
        petContent.append(petName);
    }
    return petContent.toString();
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
    switch (item.getItemId()){
        case android.R.id.home:
          finish();
          return true;
       }
    return super.onOptionsItemSelected(item);
  }
}
